﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
using Iprojects.Data;
using System.Linq;
namespace Iprojects.Forms
{
    public partial class Projec_SearchByName : Form
    {

       // private tblPersonsDB oPerson;
        private Person currentPerson;
        ZakahEntities db = new ZakahEntities();
        int familyid = 0;
        public Projec_SearchByName()
        {
            InitializeComponent();

            dtGridFamilyProjectHistory.AutoGenerateColumns = false;

         //   dtGridFamilyProjectHistory.Columns.Add("sum", "مجموع  ");
          

            
           
        }

       

       

           private void button1_Click(object sender, EventArgs e)
           {
               Person WifePerson = new Person();

               // check if there is id like that at table FamilyPerson
               //if have a relation in family person then
               bool isthereahusbandinsystem = false;
               
                   //  personDetails = this.oPerson.GetPersonDetailsbyID(txtid.Text);

                   /*  currentPerson = db.Persons.FirstOrDefault(x => x.FirstName.Contains(txtid.Text));
                     FamilyPerson family_rel = db.FamilyPersons.FirstOrDefault(x => x.Husbandid == currentPerson.IDnum || x.wifeid == currentPerson.IDnum);
                     familyid =Convert.ToInt32(family_rel.id);*/

               if (!string.IsNullOrEmpty(txtid.Text) && !string.IsNullOrEmpty(txtFullname.Text))
               {
                   var query = from p in db.Persons.Where(x => x.FirstName.Contains(txtid.Text) && x.LastName.Contains(txtFullname.Text))
                               select p;
                   dtGridFamilyProjectHistory.DataSource = query.ToList<Person>();
                   return;

               }
               if (!string.IsNullOrEmpty(txtid.Text))
                   {
                       var query = from p in db.Persons.Where(x => x.FirstName.Contains(txtid.Text))
                                   select p;
                       dtGridFamilyProjectHistory.DataSource = query.ToList<Person>();
                   }
               if (!string.IsNullOrEmpty(txtFullname.Text))
                   {
                       var query = from p in db.Persons.Where(x => x.LastName.Contains(txtFullname.Text))
                                   select p;
                       dtGridFamilyProjectHistory.DataSource = query.ToList<Person>();
                   }
                   
                   //    WifePerson = db.Persons.FirstOrDefault(x=>(x.FamilyID == familyid) && (x.IDnum != txtid.Text) );






              


           }
        }

   
    }



